package com.xxcloud.model.web;

public class JobResult {

    private long beginTime;
    private long endTime;
    private boolean isOk = false;
    private String msg = "";

    private int rows = 0;

    public JobResult() {
        this.beginTime = System.currentTimeMillis();
    }

    public static JobResult failed(String msg) {
        JobResult jobResult = new JobResult();
        jobResult.setOk(false);
        jobResult.setMsg("任务执行失败：" + msg);
        return jobResult;
    }

    public static JobResult success(String msg) {
        JobResult jobResult = new JobResult();
        jobResult.setOk(true);
        jobResult.setMsg("任务执行成功：" + msg);
        return jobResult;
    }

    public void begin() {
        this.beginTime = System.currentTimeMillis();
    }

    public JobResult finish() {
        msg = "任务执行成功，耗时 " + getCost(beginTime, System.currentTimeMillis());
        this.isOk = true;
        return this;
    }

    public long getBeginTime() {
        return beginTime;
    }

    public void setBeginTime(long beginTime) {
        this.beginTime = beginTime;
    }

    public long getEndTime() {
        return endTime;
    }

    public void setEndTime(long endTime) {
        this.endTime = endTime;
    }

    public boolean isOk() {
        return isOk;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public void setOk(boolean isOk) {
        this.isOk = isOk;
    }

    public String getMsg() {
        msg = "任务执行成功，耗时 " + getCost(beginTime, System.currentTimeMillis());
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static String getCost(long begin, long end) {
        if (end <= 0) {
            return "0毫秒";
        }
        return (end - begin) + "毫秒";
    }

}
